{include file='public/meta'}
<title>房源列表</title>
{load file='/static/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css'}
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
</head>
<body>
{include file='public/header'}
{include file='public/menu'}
<style type="text/css">
	.container-fluid{height:44px;}
</style>
<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 房源管理 <span class="c-gray en">&gt;</span> 个人房源 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="Hui-article">
		<div class="pos-a" style="width:150px;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5">
			<ul id="treeDemo" class="ztree">
			</ul>
		</div>
		<div style="margin-left:150px;">
			<div class="pd-20">
				<div class="text-c">
					<form action="{:url('admin/renter/member_show')}" method="post">
						<span class="select-box inline">
						<select name="cond" class="select">
							<option value="all">搜索全部</option>
							<option value="vill">小区</option>
							<option value="status">已租/未租</option>
							<option value="state">合租/整租</option>
							<option value="ispub">上架/下架</option>
							<option value="pub">可发布/不可发布</option>
						</select>
						</span>
						<input type="text" name="key" id="select" placeholder=" 关键字" style="width:250px" class="input-text">
						<button name="" id="" class="btn btn-success radius" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜房源</button>
					</form>
				</div>
				<div class="cl pd-5 bg-1 bk-gray mt-20"> 
					<span class="l"> 
						<a class="btn btn-success radius" href="{:url('renter_list')}"><i class="glyphicon glyphicon-sunglasses"></i> 全部房源</a></span> <span class="r">共有数据：<strong>{$count}</strong> 条
					</span> </div>
				<div class="mt-20">
					<table class="table table-border table-bordered table-bg table-hover table-sort">
						<thead>
							<tr class="text-c">
								<th width="40"><input name="" type="checkbox" value=""></th>
								<th width="40">房源编码</th>
								<!-- <th width="60">缩略图</th> -->
								<th width="40">区/县</th>
								<th width='50'>小区</th>
								<th width='60'>月租</th>
								<th width='40'>合租</th>
								<th width='40'>未租</th>
								<th width='90'>创建时间</th>
								<th width="40">房屋状态</th>
								<th width="40">发布状态</th>
								<th width="90">操作</th>
							</tr>
						</thead>
						<tbody>
							{foreach name='data' item='v'}
							<tr class="text-c va-m you">
								<td><input name="" type="checkbox" value=""></td>
								<td>{$v.rid}</td>
								<!-- <td><a onClick="product_show('{$v.addr}','renter_show.html?rid={$v.rid}','{$v.rid}')" href="javascript:;"><img width="60" class="product-thumb" src="/static/upload/owner/{$v.thumb}"></a></td> -->
								<td>{$v.area}</td>
								<td>{$v.vill}</td>
								<td>{$v.price}</td>
								<td>{if condition='$v.state == "合租"'}<button onClick="hezu2(this,{$v.rid},{$v.hid})">{$v.state}</button>{else}<button onClick="zhengzu(this,{$v.rid},'{$v.status}')">{$v.state}</button>{/if}</td>
								<td class='status'>{$v.status}</td>
								<td>{$v.time}</td>
								{if condition='$v.pub == "可以发布"'}
								<td><span class="label label-primary radius">{$v.pub}</span></td>
									{if condition='$v.ispub == 0'}
									<td class='td-status'><span class="label label-defaunt radius">已下架</span></td>
									{else /}

									<td class='td-status'><span class="label label-success radius">已发布</span></td>
									{/if}
								{else /}
								<td><span class="label label-danger radius">{$v.pub}</span></td>
								<td class='td-status'></td>
								{/if}
								<td class="td-manage">
									{assign name='rid' value='$v.rid'}
									{if condition='$v.ispub == 0'}
									<a style="text-decoration:none" onClick="product_start(this,{$rid})" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>
									{else /}
									<a style="text-decoration:none" onClick="product_stop(this,{$rid})" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>
									{/if}
									<a style="text-decoration:none" href="{:url('pub')}?rid={$v.rid}" title='准备发布' target='_blank'><i class="glyphicon glyphicon-arrow-up"></i></a>
									<a style="text-decoration:none" class="ml-5" onClick="product_show('{$v.addr}','renter_show.html?rid={$v.rid}','{$v.rid}')" href="javascript:;" title="查看"><i class="glyphicon glyphicon-picture"></i></a> 
									<a style="text-decoration:none" class="ml-5" onClick="renter_owner('张三','owner_show.html','{$v.rid}','800','550')" href="javascript:;" title="业主"><i class="glyphicon glyphicon-phone-alt"></i></a> 
									<a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$v.rid}')" href="javascript:;" title="删除房源"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
							</tr>
							{/foreach}
						</tbody>
					</table>
				</div>
			</div>
		</div>

	</div>
</section>
{include file='public/footer'}
<!--请在下方写此页面业务相关的脚本-->
{load href='/static/lib/My97DatePicker/4.8/WdatePicker.js'}
{load href='/static/lib/datatables/1.10.0/jquery.dataTables.min.js'}
{load href='/static/lib/laypage/1.2/laypage.js'}
{load href='/static/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js'}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
$().ready(function(){
	if($('select').val() == 'all'){
		$('#select').attr('disabled',true);
	}
	$('select').change(function(){
		if($('select').val() == 'all'){
			$('#select').attr('disabled',true);
		}else{
			$('#select').attr('disabled',false);
		}
	});
})
</script>
<script type="text/javascript">
var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pid",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			$.post('{:url('admin/renter/vill_select')}','id='+treeNode.id,function(res){
				$('strong').text('');
				console.log(res);
				// $('.strong').remove();
				$('strong').prepend(res.msg.length);
                $('.you').remove();
                $.each(res.msg,function(key,val){
                	var str = '<tr class="text-c va-m you">';
						str +='<td><input name="" type="checkbox" value=""></td>';
						str+='<td>'+val.rid+'</td>';
						str+='<td><a href="javascript:;"><img width="60" class="product-thumb" src="/static/upload/owner/'+val.thumb+'"></a></td>';
						str+='<td class="text-l">'+val.area+'</td>';
						str+='<td class="text-l">'+val.vill+'</td>';
						str+='<td class="text-l">'+val.price+'</td>';
						str+='<td class="text-l">'+val.state+'</td>';
						str+='<td class="text-l">'+val.checker+'</td>';
						str+='<td class="text-l">'+val.time+'</td>';
						str+='<td class="text-l">不可发布</td>';
						str+='<td class="text-l">'+val.status+'</td>';
						str+='<td class="td-status"><span class="label label-success radius">已发布</span></td>';
				str+='<td class="td-manage"><a style="text-decoration:none" onClick="product_stop(this,'+val.rid+')" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a> <a style="text-decoration:none" class="ml-5" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'+val.rid+')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td></tr>';
                	$('tbody').prepend(str);
                });
                 
                
                
            })
		}
	}
};

var zNodes = {$vinfo}

var code;

function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}

$(document).ready(function(){
	var t = $("#treeDemo");
	t = $.fn.zTree.init(t, setting, zNodes);
	demoIframe = $("#testIframe");
	demoIframe.bind("load", loadReady);
	var zTree = $.fn.zTree.getZTreeObj("tree");
	zTree.selectNode(zTree.getNodeByParam("id",'11'));
});

$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	  {"orderable":false,"aTargets":[0,7]}// 制定列不参与排序
	]
});
/*图片-添加*/
function product_add(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*图片-查看*/
function product_show(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*房源-下架*/
function product_stop(obj,id){
	layer.confirm('确认要下架吗？',function(index){
		$.post('pub_stop.html','rid='+id,function(res){
			if(res.msg == '已下架'){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,{$Think.session.rid})" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
				$(obj).remove();
				location.href = '';
			}
			layer.msg(res.msg,{icon: 5,time:1000});
		})
	});
}

/*图片-发布*/
function product_start(obj,id){
	layer.confirm('确认要发布吗？',function(index){
		$.post('pub_start.html','rid='+id,function(res){
			//res = eval('('+res+')');
			console.log(res.msg);
			if(res.msg == '已上架'){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_stop(this,{$Think.session.rid})" href="javascript:;" title="下架"><i class="Hui-iconfont">&#xe6de;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
				$(obj).remove();
			}
			layer.msg(res.msg,{icon: 6,time:1000});
		})
		
	});
}
/*图片-申请上线*/
function product_shenqing(obj,id){
	$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
	$(obj).parents("tr").find(".td-manage").html("");
	layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
}
/*业主-查看*/
function renter_owner(title,url,id,w,h){
	layer_show(title,url+'?rid='+id,w,h);		
}
/*图片-删除*/
function product_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.post('renter_del.html','rid='+id,function(res){
			$(obj).parents("tr").remove();
			layer.msg('已删除!',{icon:1,time:1000});
		})
	});
}
//查看合租房
function hezu2(obj,rid,hid){
	//layer_show('合租信息','{:url('hezu2')}'+'?rid='+rid+'&hid='+hid,800,600);
	layer.open({
		type: 2,
		area: ['800px', '500px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: '合租房查看',
		content: '{:url('hezu2')}'+'?rid='+rid+'&hid='+hid,
		end: function () {
                location.href = "{:url('member_show')}";
            }
	});
}
//整租
function zhengzu(obj,id,status){
  layer.confirm('确认要出租/回租吗？',function(index){
  	if(status == '未租'){
  		//出租
  		$.post('nozu.html','rid='+id+'&status='+status,function(res){
	      //layer_show('整租信息','{:url('zhengzu')}'+'?rid='+id,500,500);
	      layer.open({
			type: 2,
			area: ['500px', '500px'],
			fix: false, //不固定
			maxmin: true,
			shade:0.4,
			title: '整租信息',
			content: '{:url('zhengzu')}'+'?rid='+id,
			end: function () {
	                location.href = "{:url('member_show')}";
	            }
	});
	    })
  	}else{
  		//回租
  		$.post('nozu.html','rid='+id+'&status='+status,function(res){

  			layer.msg('收房成功',{icon:1,time:1000},function(){
	        	location.reload();
	      });
  		});
  	}
  	
    
  });
}

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>